package sg.edu.nus.iss.pacman.form;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.TextBox;
import javax.microedition.lcdui.TextField;

import sg.edu.nus.iss.pacman.midlet.PacManMIDlet;

/**
 * This is common screen to display message confirmation
 * 
 * @author Daniel
 *
 */
public class MessageInfo extends TextBox implements CommandListener {

	private static final String TITLE = "Confirmation";
	
	private PacManMIDlet mainApp;
	
	private String message;
	private Command cmdOK;
	
	/**
	 * Constructor for this screen
	 * 
	 * @param mainApp PacManMIDlet
	 * @param message message to be displayed
	 */
	public MessageInfo(PacManMIDlet mainApp, String message) {
		super(TITLE, message, message.length(), TextField.ANY);
		this.message = message;
		this.mainApp = mainApp;
		init();
	}
	
	/**
	 * Initializes the screen
	 */
	private void init() {
		cmdOK = new Command(PacManMIDlet.LABEL_CMD_OK, Command.OK, 1);
		
		addCommand(cmdOK);
		setCommandListener(this);
	}
	
	/**
	 * This is a method which handles command actions
	 */
	public void commandAction(Command cmd, Displayable dept) {
		if (cmd == cmdOK) {
			mainApp.displayMainMenu();
		}
	}

}
